package com.asl.website.aslMyaslIntro.controller;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.asl.website.aslMyaslIntro.domain.MyaslIntroDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.asl.common.annotation.Log;
import com.asl.common.core.controller.BaseController;
import com.asl.common.core.domain.AjaxResult;
import com.asl.common.enums.BusinessType;
import com.asl.website.aslMyaslIntro.domain.AslMyaslIntro;
import com.asl.website.aslMyaslIntro.service.IAslMyaslIntroService;
import com.asl.common.utils.poi.ExcelUtil;
import com.asl.common.core.page.TableDataInfo;

/**
 * myASL介绍Controller
 * 
 * @author ruoyi
 * @date 2025-06-02
 */
@RestController
@RequestMapping("/aslMyaslIntro/aslMyaslIntro")
public class AslMyaslIntroController extends BaseController
{
    @Autowired
    private IAslMyaslIntroService aslMyaslIntroService;
    /**
     * 获取所有myASL介绍内容（按排序）
     */
    @GetMapping("/contents")
    public AjaxResult getAllContents(
            @RequestHeader(value = "Accept-Language", defaultValue = "zh-CN") String acceptLanguage) {

        AslMyaslIntro query = new AslMyaslIntro();
        List<AslMyaslIntro> contents = aslMyaslIntroService.selectAslMyaslIntroList(query);
        if (contents.isEmpty()) {
            return AjaxResult.error("未配置任何服务内容");
        }

        List<MyaslIntroDTO> result = contents.stream()
                .map(content -> new MyaslIntroDTO(content, acceptLanguage))
                .sorted(Comparator.comparing(MyaslIntroDTO::getSortOrder)) // 按 a,b,c 排序
                .collect(Collectors.toList());

        return AjaxResult.success(result);
    }
    /**
     * 查询myASL介绍列表
     */
    @PreAuthorize("@ss.hasPermi('aslMyaslIntro:aslMyaslIntro:list')")
    @GetMapping("/list")
    public TableDataInfo list(AslMyaslIntro aslMyaslIntro)
    {
        startPage();
        List<AslMyaslIntro> list = aslMyaslIntroService.selectAslMyaslIntroList(aslMyaslIntro);
        return getDataTable(list);
    }

    /**
     * 导出myASL介绍列表
     */
    @PreAuthorize("@ss.hasPermi('aslMyaslIntro:aslMyaslIntro:export')")
    @Log(title = "myASL介绍", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AslMyaslIntro aslMyaslIntro)
    {
        List<AslMyaslIntro> list = aslMyaslIntroService.selectAslMyaslIntroList(aslMyaslIntro);
        ExcelUtil<AslMyaslIntro> util = new ExcelUtil<AslMyaslIntro>(AslMyaslIntro.class);
        util.exportExcel(response, list, "myASL介绍数据");
    }

    /**
     * 获取myASL介绍详细信息
     */
    @PreAuthorize("@ss.hasPermi('aslMyaslIntro:aslMyaslIntro:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aslMyaslIntroService.selectAslMyaslIntroById(id));
    }

    /**
     * 新增myASL介绍
     */
    @PreAuthorize("@ss.hasPermi('aslMyaslIntro:aslMyaslIntro:add')")
    @Log(title = "myASL介绍", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AslMyaslIntro aslMyaslIntro)
    {
        return toAjax(aslMyaslIntroService.insertAslMyaslIntro(aslMyaslIntro));
    }

    /**
     * 修改myASL介绍
     */
    @PreAuthorize("@ss.hasPermi('aslMyaslIntro:aslMyaslIntro:edit')")
    @Log(title = "myASL介绍", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AslMyaslIntro aslMyaslIntro)
    {
        return toAjax(aslMyaslIntroService.updateAslMyaslIntro(aslMyaslIntro));
    }

    /**
     * 删除myASL介绍
     */
    @PreAuthorize("@ss.hasPermi('aslMyaslIntro:aslMyaslIntro:remove')")
    @Log(title = "myASL介绍", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aslMyaslIntroService.deleteAslMyaslIntroByIds(ids));
    }
}
